package MP.lib;

import java.io.DataInputStream;
import java.io.IOException;

import MP.codegeneration.IllegalRuntimeException;
import MP.CompilationException;

public class Lib {
	private static final DataInputStream input = new DataInputStream(System.in);
	
	/** reads and returns an integer value from the standard input
	 *	@return int an integer number read from standard input
	 */
	public static int readInt() throws CompilationException {
		try {
			return input.readInt();
		} catch (IOException e) {
			throw new IllegalRuntimeException();
		}
	}
	
		
    /** print out the value of the integer i to the standard output
     *	@param i the value is printed out
     */
    public static void writeInt(int i) {
	    System.out.print(i);
    }
   
    /** same as putInt except that it also prints a newline
     *	@param i the value is printed out
     */	
    public static void writeIntLn(int i) {
	    System.out.println(i);
    }
    
    /** return a floating-point value read from the standard input
     *	@return float the floating-point value
     */
    public static float readReal() throws CompilationException {   
    	try {
			return input.readFloat();
		} 
    	catch (IOException e) {
			throw new IllegalRuntimeException();
		}
	}
	
    /** print out the value of the float f to the standard output
     *	@param f the floating-point value is printed out
     */
    public static void writeReal(float f){
	    System.out.print(f);
    }
    
    /** same as putFloat except that it also prints a newline
     *	@param f the floating-point value is printed out
     */
    public static void writeRealLn(float f) {
	    System.out.println(f);
    }
    
	/** reads and returns a boolean value from the standard input
	 *	@return int a boolean value read from standard input
	 */
	public static int readBool() throws CompilationException {
		try {
			return input.readInt();
		} catch (IOException e) {
			throw new IllegalRuntimeException();
		}
	}

    /** print out the value of the boolean b to the standard output
     *	@param b the boolean value is printed out
     */
    public static void writeBool(boolean b) {
	    System.out.print(b);
    }
    
    /** same as putBoolLn except that it also prints a new line
     *	@param b the boolean value is printed out
     */
    public static void writeBoolLn(boolean b) {
	    System.out.println(b);
    }
    
    /** prints the value of the string to the standard output
     *	@param a the string is printed out
     */
     public static void writeStr(String a ) {
	    System.out.print(a);
    }
    
    /** same as putString except that it also prints a new line
     *	@param a the string is printed out
     */
    public static void writeStrLn(String a){
	    System.out.println(a);
    }
    /** print out an empty line
     **/
    public static void writeLn() {
	    System.out.println();
    }
}

